home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / ncurses-5.3.lha / ncurses-5.3 / menu / m_opts.c < prev    next >
C/C++ Source or Header  |  2002-10-24  |  7KB  |  176 lines

  1. /****************************************************************************
  2.  * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
  3.  *                                                                          *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a  *
  5.  * copy of this software and associated documentation files (the            *
  6.  * "Software"), to deal in the Software without restriction, including      *
  7.  * without limitation the rights to use, copy, modify, merge, publish,      *
  8.  * distribute, distribute with modifications, sublicense, and/or sell       *
  9.  * copies of the Software, and to permit persons to whom the Software is    *
  10.  * furnished to do so, subject to the following conditions:                 *
  11.  *                                                                          *
  12.  * The above copyright notice and this permission notice shall be included  *
  13.  * in all copies or substantial portions of the Software.                   *
  14.  *                                                                          *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
  16.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
  17.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
  18.  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
  19.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
  20.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
  21.  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
  22.  *                                                                          *
  23.  * Except as contained in this notice, the name(s) of the above copyright   *
  24.  * holders shall not be used in advertising or otherwise to promote the     *
  25.  * sale, use or other dealings in this Software without prior written       *
  26.  * authorization.                                                           *
  27.  ****************************************************************************/
  28.  
  29. /****************************************************************************
  30.  *   Author:  Juergen Pfeifer, 1995,1997                                    *
  31.  *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
  32.  ****************************************************************************/
  33.  
  34. /***************************************************************************
  35. * Module m_opts                                                            *
  36. * Menus option routines                                                    *
  37. ***************************************************************************/
  38.  
  39. #include "menu.priv.h"
  40.  
  41. MODULE_ID("$Id: m_opts.c,v 1.14 2002/07/06 15:22:16 juergen Exp $")
  42.  
  43. /*---------------------------------------------------------------------------
  44. |   Facility      :  libnmenu
  45. |   Function      :  int set_menu_opts(MENU *menu, Menu_Options opts)
  46. |
  47. |   Description   :  Set the options for this menu. If the new settings
  48. |                    end up in a change of the geometry of the menu, it
  49. |                    will be recalculated. This operation is forbidden if
  50. |                    the menu is already posted.
  51. |
  52. |   Return Values :  E_OK           - success
  53. |                    E_BAD_ARGUMENT - invalid menu options
  54. |                    E_POSTED       - menu is already posted
  55. +--------------------------------------------------------------------------*/
  56. NCURSES_EXPORT(int)
  57. set_menu_opts (MENU * menu, Menu_Options opts)
  58. {
  59.   opts &= ALL_MENU_OPTS;
  60.  
  61.   if (opts & ~ALL_MENU_OPTS)
  62.     RETURN(E_BAD_ARGUMENT);
  63.  
  64.   if (menu)
  65.     {
  66.       if ( menu->status & _POSTED )
  67.     RETURN(E_POSTED);
  68.  
  69.       if ( (opts&O_ROWMAJOR) != (menu->opt&O_ROWMAJOR))
  70.     {
  71.       /* we need this only if the layout really changed ... */
  72.       if (menu->items && menu->items[0])
  73.         {
  74.           menu->toprow  = 0;
  75.           menu->curitem = menu->items[0];
  76.           assert(menu->curitem);
  77.           set_menu_format( menu, menu->frows, menu->fcols );
  78.         }
  79.     }
  80.  
  81.       menu->opt = opts;
  82.  
  83.       if (opts & O_ONEVALUE)
  84.     {
  85.       ITEM **item;
  86.  
  87.       if ( ((item=menu->items) != (ITEM**)0) )
  88.         for(;*item;item++)
  89.           (*item)->value = FALSE;
  90.     }
  91.  
  92.       if (opts & O_SHOWDESC)    /* this also changes the geometry */
  93.     _nc_Calculate_Item_Length_and_Width( menu );
  94.     }
  95.   else
  96.     _nc_Default_Menu.opt = opts;
  97.  
  98.   RETURN(E_OK);
  99. }
  100.  
  101. /*---------------------------------------------------------------------------
  102. |   Facility      :  libnmenu
  103. |   Function      :  int menu_opts_off(MENU *menu, Menu_Options opts)
  104. |
  105. |   Description   :  Switch off the options for this menu. If the new settings
  106. |                    end up in a change of the geometry of the menu, it
  107. |                    will be recalculated. This operation is forbidden if
  108. |                    the menu is already posted.
  109. |
  110. |   Return Values :  E_OK           - success
  111. |                    E_BAD_ARGUMENT - invalid options
  112. |                    E_POSTED       - menu is already posted
  113. +--------------------------------------------------------------------------*/
  114. NCURSES_EXPORT(int)
  115. menu_opts_off (MENU *menu, Menu_Options  opts)
  116. {
  117.   MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
  118.                          NULL menu itself to adjust its behaviour */
  119.  
  120.   opts &= ALL_MENU_OPTS;
  121.   if (opts & ~ALL_MENU_OPTS)
  122.     RETURN(E_BAD_ARGUMENT);
  123.   else
  124.     {
  125.       Normalize_Menu(cmenu);
  126.       opts = cmenu->opt & ~opts;
  127.       return set_menu_opts( menu, opts );
  128.     }
  129. }
  130.  
  131. /*---------------------------------------------------------------------------
  132. |   Facility      :  libnmenu
  133. |   Function      :  int menu_opts_on(MENU *menu, Menu_Options opts)
  134. |
  135. |   Description   :  Switch on the options for this menu. If the new settings
  136. |                    end up in a change of the geometry of the menu, it
  137. |                    will be recalculated. This operation is forbidden if
  138. |                    the menu is already posted.
  139. |
  140. |   Return Values :  E_OK           - success
  141. |                    E_BAD_ARGUMENT - invalid menu options
  142. |                    E_POSTED       - menu is already posted
  143. +--------------------------------------------------------------------------*/
  144. NCURSES_EXPORT(int)
  145. menu_opts_on (MENU * menu, Menu_Options opts)
  146. {
  147.   MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
  148.                          NULL menu itself to adjust its behaviour */
  149.  
  150.   opts &= ALL_MENU_OPTS;
  151.   if (opts & ~ALL_MENU_OPTS)
  152.     RETURN(E_BAD_ARGUMENT);
  153.   else
  154.     {
  155.       Normalize_Menu(cmenu);
  156.       opts = cmenu->opt | opts;
  157.       return set_menu_opts(menu, opts);
  158.     }
  159. }
  160.  
  161. /*---------------------------------------------------------------------------
  162. |   Facility      :  libnmenu
  163. |   Function      :  Menu_Options menu_opts(const MENU *menu)
  164. |
  165. |   Description   :  Return the options for this menu.
  166. |
  167. |   Return Values :  Menu options
  168. +--------------------------------------------------------------------------*/
  169. NCURSES_EXPORT(Menu_Options)
  170. menu_opts (const MENU *menu)
  171. {
  172.   return (ALL_MENU_OPTS & Normalize_Menu( menu )->opt);
  173. }
  174.  
  175. /* m_opts.c ends here */
  176.